package com.wbcs.exception;

import java.io.PrintStream;
import java.io.PrintWriter;

public class WbcsDataImportException extends RuntimeException
{
    private static final long serialVersionUID=3225488091392810564L;
    
    private Throwable mRootCause=null;

    public WbcsDataImportException()
    {}

    public WbcsDataImportException(String message)
    {
        super(message);

    }

    public WbcsDataImportException(Throwable t)
    {
        super(t);
        mRootCause=t;
    }

    public WbcsDataImportException(String mess,Throwable t)
    {
        super(mess,t);
        mRootCause=t;
    }

    public Throwable getRootCause()
    {
        return mRootCause;
    }

    public String getRootCauseMessage()
    {
        String rcmessage=null;
        if(getRootCause()!=null)
        {
            if(getRootCause().getCause()!=null)
            {
                rcmessage=getRootCause().getCause().getMessage();
            }
            rcmessage=(rcmessage==null)?getRootCause().getMessage():rcmessage;
            rcmessage=(rcmessage==null)?super.getMessage():rcmessage;
            rcmessage=(rcmessage==null)?"NONE":rcmessage;
        }
        return rcmessage;
    }

    @Override
	public void printStackTrace()
    {
        super.printStackTrace();
        if(mRootCause!=null)
        {
            System.out.println("--- ROOT CAUSE ---");
            mRootCause.printStackTrace();
        }
    }

    @Override
	public void printStackTrace(PrintStream s)
    {
        super.printStackTrace(s);
        if(mRootCause!=null)
        {
            s.println("--- ROOT CAUSE ---");
            mRootCause.printStackTrace(s);
        }
    }

    @Override
	public void printStackTrace(PrintWriter s)
    {
        super.printStackTrace(s);
        if(null!=mRootCause)
        {
            s.println("--- ROOT CAUSE ---");
            mRootCause.printStackTrace(s);
        }
    }
}
